        package companyTest.tianrongxin;

        import java.util.Scanner;

        public class Main2 {
            public static void main(String[] args) {
                Scanner scanner=new Scanner(System.in);
                int len1=scanner.nextInt();
                int []arr1=new int[len1];
                for (int i = 0; i < len1; i++) {
                    arr1[i]=scanner.nextInt();
                }
                int len2=scanner.nextInt();
                int []arr2=new int[len2];
                for (int i = 0; i < len2; i++) {
                    arr2[i]=scanner.nextInt();
                }
                int dp[][]=new int[len1+1][len2+1];
                int max=0;
                for (int i = 0; i < len1; i++) {
                    for (int j = 0; j < len2; j++) {
                        if (arr1[i]==arr2[j]){
                            dp[i+1][j+1]=dp[i][j]+1;
                            max=Math.max(max,dp[i+1][j+1]);
                        }else {
                            dp[i+1][j+1]=0;
                        }
                    }
                }
                System.out.println(max);
            }
        }
